package cn.edu.ujn.park.service;

import cn.edu.ujn.park.dao.User;
import cn.edu.ujn.park.dao.UserMapper;
import cn.edu.ujn.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService{

    @Autowired
    private UserMapper userMapper;
    @Override
    public User checkLogin(User user) {

        return userMapper.checkLogin(user);

    }

    @Override
    public Page<User> selectAll(User user) {
        Page<User> page = new Page<>();
        List<User> list = userMapper.selectAll(user);
        Integer count=userMapper.selectCount(user);


        page.setPage(user.getStart());
        page.setRows(list);
        page.setSize(user.getRows());
        page.setTotal(count);

        return page;
    }

    @Override
    public void insert(User user) {
        userMapper.insert(user);
    }

    @Override
    public User getUserById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateByPrimaryKey(User user) {
        userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public void deleteByPrimaryKey(Integer id) {
        userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public String selectUserName(Integer userId) {
        return userMapper.selectUserName(userId);
    }

    @Override
    public List<User> select() {
        return userMapper.select();
    }

}
